# -*- coding:utf-8 -*-
from apps.models import Kind, News
from flask import Blueprint, render_template

data = Blueprint('data', __name__)


@data.route('/news/')
def index():
    """
    给echarts传递参数生成统计图并展示
    :return:
    """
    result_list = []
    type_list = []
    new_count_list = []
    kind_list = Kind.query.all()
    for kind in kind_list:
        result = {}
        type = kind.type
        count = News.query.filter_by(type_id=kind.type_id).count()
        type_list.append(type)
        new_count_list.append(count)
        result['name'] = type
        result['value'] = count
        result_list.append(result)
    return render_template("echarts/index.html", type_list=type_list, new_count_list=new_count_list,
                           result_list=result_list)
